package com.ce.cetag.tags.menu;

import java.io.IOException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

public class MenuItemTag extends TagSupport
{
  private String id;
  private String onMousedown;
  private String onClick;
  private String target;
  private String pageLinker;
  private String menuName;
  private String splitClassName;
  private MenuBarTag parent;
  private String onDblClick;

  public int doStartTag()
    throws JspTagException
  {
    StringBuffer out = new StringBuffer();
    if ((getPageLinker() == null) || ("".equals(getPageLinker()))) {
      setPageLinker("#");
      setTarget("");
    } else {
      if ((getTarget() == null) || ("".equals(getTarget())))
        setTarget("_blank");

      setOnClick("opener=null;self.close();");
    }
    if (this.parent.getPopupMenu().booleanValue())
      out.append("<tr>");

    out.append("<td id=\"" + getId() + "\"");
    if (getOnMousedown() != null)
      out.append(" onMousedown=\"" + getOnMousedown() + "\" ");

    if (getOnClick() != null)
    {
      out.append(" onClick=\"" + getOnClick() + "\"");
    }
    if (getOnDblClick() != null)
    {
      out.append(" onDblClick=\"" + getOnDblClick() + "\"");
    }
    out.append(">");
    out.append("<a onFocus=\"this.blur()\"  ");

    out.append("href=\"" + getPageLinker() + "\" ");
    out.append("target=\"" + getTarget() + "\" >" + getMenuName() + "</a>");

    out.append("</td>");

    if (this.parent.getPopupMenu().booleanValue())
      out.append("</tr>");
    else {
      out.append("<td class=\"" + getSplitClassName() + "\"></td>");
    }

    try
    {
      this.pageContext.getOut().write(out.toString());
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    return 1;
  }

  public int doEndTag()
    throws JspTagException
  {
    return 6;
  }

  public void setParent(Tag tag)
  {
    this.parent = ((MenuBarTag)tag);
  }

  public String getOnDblClick()
  {
    return this.onDblClick;
  }

  public void setOnDblClick(String onDblClick)
  {
    this.onDblClick = onDblClick;
  }

  public String getId()
  {
    return this.id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getOnClick() {
    return this.onClick;
  }

  public void setOnClick(String onClick) {
    this.onClick = onClick;
  }

  public String getOnMousedown()
  {
    return this.onMousedown;
  }

  public void setOnMousedown(String onMousedown) {
    this.onMousedown = onMousedown;
  }

  public String getTarget() {
    return this.target;
  }

  public void setTarget(String target)
  {
    this.target = target;
  }

  public String getMenuName() {
    return this.menuName;
  }

  public void setMenuName(String menuName) {
    this.menuName = menuName;
  }

  public String getPageLinker() {
    return this.pageLinker;
  }

  public void setPageLinker(String pageLinker) {
    this.pageLinker = pageLinker;
  }

  public String getSplitClassName() {
    return this.splitClassName;
  }

  public void setSplitClassName(String splitClassName) {
    this.splitClassName = splitClassName;
  }

  public void release()
  {
    super.release();
    this.id = null;
    this.onMousedown = null;
    this.onClick = null;
    this.target = null;
    this.pageLinker = null;
    this.menuName = null;
    this.splitClassName = null;
    this.parent = null;
    this.onDblClick = null;
  }
}